package ReferenceCasting_package;

class X 
{
	void do1()
	{
		System.out.println("X");
	}
}
class Y extends X
{
	void do2()
	{
		System.out.println("Y");
	}
}

public class test2 {
	public static void main(String[] args) 
	{
		X x1 = new X();
		X x2 = new Y();
		Y y1 = new Y();
		
		//x1.do1();
		//x2.do2(); //method do2() is undefined for type X.
		Y y2 = (Y)x2;
		//y2.do1();
		//y2.do2();
		// (Y)x2.do1(); // actually it is (Y)(x2.do1())
		//((Y)x2).do1();
		
		X x3 = (Y)new X();
		x3.do1(); // run time error:  ClassCastException
		
	}

}
